package ar.com.photo_admin.domain.price_strategies

import ar.com.photo_admin.domain.*
import grails.plugins.springsecurity.Secured

class PriceStrategyDiscountOverAmountPhotos extends PriceStrategy {

	Integer discount
	
	Integer amountCopies
	
	Float calculatePrice(PurchaseOrder purchaseOrder) {
		Float basePrice = super.calculatePrice(purchaseOrder)	
		Float totalPrice = basePrice
		
		if (purchaseOrder.calculateAmountOfItems() >= amountCopies){
			totalPrice = ((100-discount) * basePrice) / 100
		}
		
		return totalPrice
	}
	
    static constraints = {
		amountCopies(min:0)
		discount(min:0,max:100)
    }
	
	String toString(){
		return "Comprando mas de ${amountCopies} copias, se hace un descuento de ${discount}%"
	}
	
	def representsADiscount(){
		return true
	}
}
